<%# locals: (app:, problem:) %>

<% if app.issue_tracker_configured? %>
  <% tracker = app.issue_tracker %>
  <% tracker_type = tracker.type %>

  <% if problem.issue_link.present? %>
    <span>
      <%= link_to problem.issue_link, class: "goto-issue issue-tracker-button" do %>
        <img class="button-icon" src="<%= tracker_type.icons[:goto] %>">
        go to issue
      <% end %>
    </span>

    <span>
      <%= link_to unlink_issue_app_problem_path(app, problem),
          method: :delete,
          data: { confirm: "Unlink err issues?" },
          class: "unlink-issue issue-tracker-button" do %>
        <img class="button-icon" src="<%= tracker_type.icons[:create] %>">
        unlink issue
      <% end %>
    </span>

    <% if tracker.tracker.respond_to?(:close_issue) %>
      <span>
        <%= link_to close_issue_app_problem_path(app, problem),
            method: :post,
            class: "close-issue" do %>
          <img class="button-icon" src="<%= tracker_type.icons[:create] %>">
          close issue
        <% end %>
      </span>
    <% end %>

  <% elsif problem.issue_link == "pending" %>
    <span class="disabled">
      <%= link_to "#", class: "create-issue issue-tracker-button" do %>
        <img class="button-icon" src="<%= tracker_type.icons[:inactive] %>">
        creating...
      <% end %>
    </span>
    <%= link_to "retry", create_issue_app_problem_path(app, problem), method: :post %>

  <% else %>
    <span>
      <%= link_to create_issue_app_problem_path(app, problem),
          method: :post,
          class: "create-issue issue-tracker-button" do %>
        <img class="button-icon" src="<%= tracker_type.icons[:create] %>">
        create issue
      <% end %>
    </span>
  <% end %>
<% end %>
